<?php

define('IN_OS', true);

require('../../lib_common.php');
require('../../cls_mysql.php');
require('../../../data/config.php');

$current_time  = time() - date('Z');

$db = new cls_mysql($db_host, $db_user, $db_pass, $db_name, 'utf8');

$sql = 'select relating_order_id from open_order_suspend where end_time >0 and end_time <= '.$current_time;
$res = $db->getAll($sql);

$arr = array('process_status' => 0);
$sql = 'update open_order_suspend set process_status = 1 , process_mode = 4 , process_user = "后台计划任务" where relating_order_id = ';

foreach($res as $order_id)
{
	$order_id = $order_id['relating_order_id'];
	$sql_order = 'select order_sn,order_status,shipping_status,pay_status from open_order_info where  order_id = '.$order_id;
	$order = $db->getRow($sql_order);
	
	$db->autoExecute('open_order_info',
        $arr, 'UPDATE', "order_id = '$order_id'");	
	
	$username = '计划任务';
	$current_time  = time() - date('Z');       

	$sql2 = 'INSERT INTO open_order_action (order_id, action_user, order_status, shipping_status, pay_status, action_note, log_time) ' .
            "SELECT order_id, '$username', '$order[order_status]', '$order[shipping_status]', '$order[pay_status]', '解挂订单-计划任务自动解挂', '" .$current_time. "' " .'FROM open_order_info WHERE order_sn = '.$order['order_sn'];
	$db->query($sql2);
	
    $db->query($sql.$order_id);
}

?>